package net.huashitong.taskjob.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.taskjob.entity.JobGroup;
import net.huashitong.taskjob.filter.JobGroupFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class JobGroupDao extends StringDao<JobGroup> {

    /**
     * 获取督查组表列表
     *
     * @param
     * @return
     */
    public JobGroup getJobInfobyCode(String code) {
        GenericQuery query = createQuery("obj");

        query.append(" and obj.groupCode=:groupCode").setParam("groupCode", code);

        return query.singleResult();
    }
    /**
     * 获取督查组表列表
     *
     * @param
     * @return
     */
    public JobGroup getJobInfobyName(String name) {
        GenericQuery query = createQuery("obj");

        query.append(" and obj.groupName=:groupName").setParam("groupName", name);

        return query.singleResult();
    }

    /**
     * 获取督查组表列表
     *
     * @param
     * @return
     */
    public List<JobGroup> queryByFilter(JobGroupFilter filter) {
        GenericQuery query = createQuery("obj");
        if (StringUtils.isNotBlank(filter.getGroupCode())) {
            query.append(" and obj.groupCode=:groupCode").setParam("groupCode", filter.getGroupCode());
        }
        if (StringUtils.isNotBlank(filter.getGroupName())) {
            query.append(" and obj.groupName=:groupName").setParam("groupName",
                    StringUtils.getLikewords(filter.getGroupCode()));
        }
        if (StringUtils.isNotBlank(filter.getGroupDuty())) {
            query.append(" and obj.groupDuty=:groupDuty").setParam("groupDuty", filter.getGroupDuty());
        }
        if (StringUtils.isNotBlank(filter.getGroupContact())) {
            query.append(" and obj.groupContact=:groupContact").setParam("groupContact",
                    StringUtils.getLikewords(filter.getGroupContact()));
        }
        if (StringUtils.isNotBlank(filter.getGroupCloum())) {
            query.append(" and obj.groupCloum=:groupCloum").setParam("groupCloum", filter.getGroupCloum());
        }

        return query.listResult(filter);
    }

}
